<?php
namespace app\model;

class UserToken extends BaseModel
{
    // 设置表名
    protected $name = 'user_tokens';
    
    // 字段类型转换
    protected $type = [
        'created_at' => 'timestamp',
        'expired_at' => 'timestamp',
        'delete_time' => 'timestamp',
        'is_revoked' => 'integer'
    ];
    
    // 关联用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 检查令牌是否有效
     */
    public function isValid()
    {
        return !$this->is_revoked && $this->expired_at > time();
    }
} 